package labox.innovation.gameserver.network.clientpackets;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javolution.util.FastList;
import labox.innovation.gameserver.model.L2Effect;
import labox.innovation.gameserver.model.actor.instance.FuzePcInstance;
import labox.innovation.gameserver.network.serverpackets.EffectStats;
import labox.innovation.gameserver.network.serverpackets.EffectStats.Effect;
import labox.innovation.gameserver.templates.skills.L2EffectType;

/**
 * 客户端请求  所有效果状态
 * @author zjj
 *
 */
public class RequestEffectBuff extends L2GameClientPacket {

	private static final String RequestEffectBuff = "[C] 0x57 RequestEffectBuff";
	
	private static final Logger _log = LoggerFactory.getLogger(RequestEffectBuff.class.getName());

	@Override
	public String getType() {
		return RequestEffectBuff;
	}

	@Override
	protected void readImpl() {
		// TODO Auto-generated method stub

	}

	@Override
	protected void runImpl() {

		if(_log.isDebugEnabled()){
			_log.debug("请求角色状态");
		}

		FuzePcInstance player = getClient().getActiveChar();
		if (player == null) {
			if(_log.isDebugEnabled()){
				_log.debug("角色不存在");
			}
			return;
		}

		if (player.getEffectList() == null) {
			_log.debug("效果链为空");
			return;
		}

		EffectStats _effects = null;

		FastList<L2Effect> effectBuff = player.getEffectList().getBuffs();
		if (effectBuff != null) {
			if (_effects == null) {
				_effects = new EffectStats();
			}

			for (L2Effect e : effectBuff) {
				if (e.getEffectType() == L2EffectType.SIGNET_GROUND) {
					continue;
				}

				if (e.getInUse() && e.getShowIcon()) {
					_effects.add(new Effect(1, e.getRemainTime(), e.getSkill().getName(), e.getEffectType().ordinal(), e.getSkill().getId(), e.getSkill().getLevel(), false));
				}

			}

		}

		effectBuff = player.getEffectList().getDebuffs();
		if (effectBuff != null) {

			if (_effects == null) {
				_effects = new EffectStats();
			}

			for (L2Effect e : effectBuff) {
				if (e.getEffectType() == L2EffectType.SIGNET_GROUND) {
					continue;
				}

				if (e.getInUse() && e.getShowIcon()) {
					_effects.add(new Effect(e.getEffectIconId(), e.getRemainTime(), e.getSkill().getName(), e.getEffectType().ordinal(), e.getSkill().getId(), e.getSkill().getLevel(), true));
				}

			}

		}

		if (_effects != null)
			player.sendPacket(_effects);

	}

}
